package com.mofum.msdom.excel.demo;

import com.mofum.msdom.excel.demo.model.TestModel;
import com.mofum.msdom.excel.demo.model.TestModel2;
import com.mofum.msdom.excel.writer.IExcelWriter;
import com.mofum.msdom.excel.writer.impl.MultiAnnotationExcelWriterImpl;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 多个类型写入测试例子
 *
 * @author 1615690513@qq.com
 * @since 2018/11/26 0026 15:09
 */
public class MultiWriteDemo {

    public static void main(String[] args) throws IOException {
        //输出流
        FileOutputStream out = new FileOutputStream("002.xlsx");
        try {

            //数据
            List<TestModel> datas = createDatas();

            List<TestModel2> datas2 = createDatas2();

            //数据写入器
            IExcelWriter writer = new MultiAnnotationExcelWriterImpl<TestModel>();

            //写入数据
            writer.dataType(TestModel.class).start(out).write(datas)
                    .addSheet(TestModel2.class).write(3, datas2).end();
        } finally {
            out.close();
        }


    }

    /**
     * 创建数据
     */
    private static List<TestModel> createDatas() {
        List<TestModel> list = new ArrayList<>();

        list.add(new TestModel("TEST1", "TEST1", "2018-09-01 10:10:10", BigDecimal.ONE));
        list.add(new TestModel("TEST2", "TEST2", "2018-09-01 10:10:10", BigDecimal.ZERO));
        list.add(new TestModel("TEST3", "TEST3", "2018-09-01 10:10:10", BigDecimal.TEN));

        return list;
    }

    /**
     * 创建数据
     */
    private static List<TestModel2> createDatas2() {
        List<TestModel2> list = new ArrayList<>();

        list.add(new TestModel2("TEST4", "TEST4", "2018-09-01 10:10:10", BigDecimal.ONE, "SYSTEM"));
        list.add(new TestModel2("TEST5", "TEST5", "2018-09-01 10:10:10", BigDecimal.ZERO, "SYSTEM"));
        list.add(new TestModel2("TEST6", "TEST6", "2018-09-01 10:10:10", BigDecimal.TEN, "SYSTEM"));

        return list;
    }
}
